import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Recommend extends StatelessWidget {
  final List recommendList;

  Recommend({Key key, this.recommendList}) : super(key: key);

  Widget _renderTitleWidget() {
    return Container(
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.fromLTRB(10.0, 2.0, 0, 5.0),
      decoration: BoxDecoration(
          color: Colors.white,
          border:
              Border(bottom: BorderSide(width: 1.0, color: Colors.black12))),
      child: Text("商品推荐", style: TextStyle(color: Colors.red)),
    );
  }

  Widget _renderRecommendList() {
    return Container(
      height: ScreenUtil().setHeight(330.0),
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: this.recommendList.length,
        itemBuilder: (context, index) {
          return this._renderItem(index);
        },
      ),
    );
  }

  Widget _renderItem(int index) {
    return InkWell(
      onTap: () {
        print("$index");
      },
      child: Container(
        height: ScreenUtil().setHeight(330.0),
        width: ScreenUtil().setWidth(250.0),
        padding: EdgeInsets.all(8.0),
        decoration: BoxDecoration(
            color: Colors.white,
            border:
                Border(left: BorderSide(width: 1.0, color: Colors.black12))),
        child: Column(
          children: <Widget>[
            Container(
              height: ScreenUtil().setHeight(200.0),
              child: Image.network(this.recommendList[index]["image"],
                  fit: BoxFit.cover),
            ),
            Text("￥${recommendList[index]['mallPrice']}"),
            Text(
              "￥${recommendList[index]['price']}",
              style: TextStyle(
                  decoration: TextDecoration.lineThrough, color: Colors.grey),
            )
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(0, 10.0, 0, 0),
      child: Column(
        children: <Widget>[
          this._renderTitleWidget(),
          this._renderRecommendList()
        ],
      ),
    );
  }
}
